export default {
	getRandomArrayElements(arr, count) {
	    var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
	    while (i-- > min) {
	        index = Math.floor((i + 1) * Math.random());
	        temp = shuffled[index];
	        shuffled[index] = shuffled[i];
	        shuffled[i] = temp;
	    }
	    return shuffled.slice(min);
	},
	parseColor(hexStr) {
		return hexStr.length === 4 ? hexStr.substr(1).split('').map(function(s) {
			return 0x11 * parseInt(s, 16);
		}) : [hexStr.substr(1, 2), hexStr.substr(3, 2), hexStr.substr(5, 2)].map(function(s) {
			return parseInt(s, 16);
		})
	},

	// zero-pad 1 digit to 2
	pad(s) {
		return (s.length === 1) ? '0' + s : s;
	},
	cutarray(arr) {
	    let obj = {};    //obj用来记录该项重复出现了几次
	    let brr = [];    //brr是去重后的数组
	    arr.forEach((item) => {
	        if (obj[item] == undefined) {
	        obj[item] = 1;
	        brr.push(item);
	        } else {
	            obj[item] += 1;
	        } 
	    });
		console.log(obj)
	    return brr;
	}
	
	,
	gradientColors(start, end, steps, gamma) {
		var i, j, ms, me, output = [],
			so = [];
		gamma = gamma || 1;
		var normalize = function(channel) {
			return Math.pow(channel / 255, gamma);
		};
		start = this.parseColor(start).map(normalize);
		end = this.parseColor(end).map(normalize);
		for (i = 0; i < steps; i++) {
			ms = i / (steps - 1);
			me = 1 - ms;
			for (j = 0; j < 3; j++) {
				so[j] = this.pad(Math.round(Math.pow(start[j] * me + end[j] * ms, 1 / gamma) * 255).toString(16));
			}
			output.push('#' + so.join(''));
		}
		return output;
	}

}
